package com.example.demo.bizhan.distributelock.service;

import com.example.demo.bizhan.distributelock.dao.ItemsDAO;
import com.example.demo.bizhan.distributelock.dao.OrdersDAO;
import com.example.demo.bizhan.distributelock.domain.Items;
import com.example.demo.bizhan.distributelock.domain.Orders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @description: xxx
 * @time: 2020/11/2 10:54
 * @author: baojinlong
 **/
@Service
@Slf4j
public class OrdersService {
    @Autowired
    private OrdersDAO ordersDAO;

    public boolean save(String itemId) {
        try {
            Orders orders = new Orders();
            orders.setId(UUID.randomUUID().toString());
            orders.setItemId(itemId);
            ordersDAO.save(orders);
            log.info("订单创建成功,itemId={}", itemId);
            return true;
        } catch (Exception e) {
            log.error("订单创建失败", e);
            return false;
        }
    }
}
